home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Subject: Re: #include "" for large
- Message-ID: <DpuM5o.8LI@rci.ripco.com>
- X-Nntp-Sender: mambuhl@foley.ripco.com
- Sender: usenet@rci.ripco.com (Net News Admin)
- Organization: Ripco Internet BBS Chicago
- Date: Sun, 14 Apr 1996 10:51:22 GMT
-
- "Carlos Diaz (CS)" <cdiaz@eng.usf.edu>
- in <Pine.SUN.3.92.960411195730.24973A-100000@suntan> asks:
-
- [I have included the entire question from cdiaz at EOM, so that anyone
- who might be a better parser than I but missed the original posting
- might be able to help him.]
-
- Since you don't actually tell us what you are doing, I will guess that
- you have something like:
-
- /* --- situation 1 --- */
- /* part2.h */
- #define EQUAL 0
- int somefunction(int);
- /* main.c */
- #include "part2.h"
- int main() {
- /* code */
- return 0;
- }
- /* part2.c */
- int somefunction(int somearg)
- {
- return (somearg == EQUAL);
- }
-
- This properly would give a diagnostic that EQUAL is undefined in
- part2.c.
-
- /* --- situation 2 --- */
- /* part2.h */
- #define EQUAL 0
- int somefunction(int);
- /* main.c */
- #include "part2.h"
- #define EQUAL 0
- int main() {
- /* code */
- return 0;
- }
- /* part2.c */
- int somefunction(int somearg)
- {
- return (somearg == EQUAL);
- }
-
- This properly would give a diagnostic that EQUAL is undefined in
- part2.c and a diagnostic that EQUAL is multiply defined in main.c.
-
- /* -- An answer, if the above is what is happening -- */
- Put your #defines into a header (as you are doing):
- /* defines.h */
- #define EQUAL 0
- int somefunction(int);
- Do _not_ put #defines in the *.c files, but in each, include the
- definition header:
- /* part1.c */
- #include "defines.h"
- int main() {
- /* code */
- return 0;
- }
- /* part2.c */
- #include "defines.h"
- int somefunction(int somearg)
- {
- return (somearg == EQUAL);
- }
-
-
- [Original question follows]
-
- > I've been writing short two part programs using the #include "filename"
- >preprocessor.
- > I call one file main.c and the other part2.c, for which there is a
- >prototype header file part2.h.
- > All works well when I compile the programs, except when part2.h has
- >#define constants (I've been advised by my professor to use #define for
- >constants over 'const type var_name'). My compiler returns a fatal error
- >reporting that the symbol in the #define is not defined.
- > For example if #define EQUAL 0 is part of part2.h, I'm told that the
- >symbol EQUAL is not defined. But if I put the #define inside main.c, I'm
- >told that I've defined EQUAL TWICE, once in part2.h and again within
- >main. The book we're using in class is not helping at all in this subject,
- >and I cannot figure out why everything else is recognized, except #define
- >constants. Can anyone here help? If the answer to this is in the FAQ, just
- >tell me where to download it from. Thanks!
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-